package cn.js.sip.rat.system.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @ClassName: cn.js.sip.rat.system.util
 * @Description: TODO
 * @author: xuxiaoli
 * @Date: 2020-01-02   21:42
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {

    private static ApplicationContext ctx;

    public static ApplicationContext getApplicationContext() {
        return SpringContextUtil.ctx;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringContextUtil.ctx == null) {
            SpringContextUtil.ctx = applicationContext;
        }
    }

    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }
}
